import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';

import 'package:yt_devops/styles/styles.dart';

class CompChartLenged extends StatelessWidget {
  List<ChartLegendItem> list;
  CompChartLenged(
    this.list, {
    super.key,
  });

  TextStyle minLightText = TextStyles.f12;

  @override
  Widget build(BuildContext context) {
    return Row(
      mainAxisAlignment: MainAxisAlignment.end,
      children: [
        ...list.map((e) => Padding(
            padding: EdgeInsets.only(left: 10.w),
            child: Row(
              children: [
                Container(
                  width: 10.w,
                  height: 10.h,
                  decoration:
                      BoxDecoration(shape: BoxShape.circle, color: e.color),
                ),
                SizedBox(
                  width: 4.w,
                ),
                Text(
                  e.title,
                  style: minLightText,
                ),
                SizedBox(
                  width: 4.w,
                ),
                Text(
                  '(${(e.total == 0 ? 0 : e.amount / e.total * 100).toStringAsFixed(2)}%)',
                  style: minLightText,
                ),
              ],
            )))
      ],
    );
  }
}

class ChartLegendItem {
  double amount;
  Color color;
  double total;
  String title;
  ChartLegendItem(
      {required this.color,
      required this.amount,
      required this.total,
      required this.title});
}
